package com.example.clock.basicClass;

import static androidx.constraintlayout.widget.StateSet.TAG;

import android.annotation.SuppressLint;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import androidx.annotation.NonNull;

import com.example.clock.controlClass.SqlController;

import java.sql.Array;
import java.sql.SQLOutput;
import java.util.ArrayList;

public class Tags {
    private String bigTag;
    private ArrayList<String> smallTags;

    public static void main(String[ ] args) {

    }




    public Tags(String bigTag, ArrayList<String> smallTags) {
        this.bigTag = bigTag;
        this.smallTags = smallTags;
    }

    public String getBigTag() {
        return bigTag;
    }

    public void setBigTag(String bigTag) {
        this.bigTag = bigTag;
    }

    public ArrayList<String> getSmallTags() {
        return smallTags;
    }

    public void setSmallTags(ArrayList<String> smallTags) {this.smallTags = smallTags;}

    @SuppressLint("Range")
    public static String[] getStringBigTags(SQLiteDatabase db){
        //获取bigtags的所有列
        Cursor c = db.query("bigtags",new String[]{"bigTag"},null,null,null,null,null);
        //转化为String
        String[] s = new String[c.getCount()];
        int j = 0;
        c.moveToFirst();
        do {
            Log.d(TAG, "getStringBigTags: "+ c.getString(c.getColumnIndex("bigTag")));
            s[j] = c.getString(c.getColumnIndex("bigTag"));
            j++;
        }while(c.moveToNext());

        ArrayList arrayList = SqlController.getAllTags(db);
        int bigCount = arrayList.size();
        String[] bigTagsString = new String[bigCount];
        for(int i = 0;i < bigCount;i ++){
            Tags t = (Tags)arrayList.get(i);
            bigTagsString[i] = t.bigTag;
        }

        return HelpFunc.completeArray(bigTagsString,s);
    }
    public static String[][] getStringSmallTags(SQLiteDatabase db){
        ArrayList arrayList = SqlController.getAllTags(db);
        String[] bigTagsArray = getStringBigTags(db);
        int bigCount = bigTagsArray.length;
        //获取小标签最大容量
        int maxSmallCount = 0;
        for(int i = 0;i < arrayList.size();i++){//获取小标签最大容量
            Tags t= (Tags)arrayList.get(i);//获取Tags类实例
            ArrayList<String> smallTags = t.getSmallTags();//获取小标签组
            if(maxSmallCount < smallTags.size()){//获取最大容量
                maxSmallCount = smallTags.size();
            }
        }

        //获取所有小标签
        String[][] smallTagsString = new String[bigCount][maxSmallCount];
        for(int i = 0;i < arrayList.size();i ++){
            Tags t= (Tags)arrayList.get(i);//获取Tags实例
            for(int j = 0;j <maxSmallCount; j++){//获取小标签
                if(j < t.getSmallTags().size())
                smallTagsString[i][j] = t.smallTags.get(j);
                else smallTagsString[i][j] = "";
            }
        }

        //把没有标签的填满
        for(int i = arrayList.size();i < bigCount;i++){
            for(int j = 0;j <maxSmallCount; j++){//获取小标签
                smallTagsString[i][j] = "";
            }
        }
        return smallTagsString;

    }


}